package fudan.se.project.repository.entity.conference.post;

import fudan.se.project.domain.conference.post.Post;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PostRepository extends CrudRepository<Post, Long> {

    Post findById(long id);

    Post findByPaperId(long id);

    @Query("select post from Post post " +
            "where " +
            "post.paper.id=:id " +
            "and post not in (select distinct rebuttal.post from Rebuttal rebuttal )  "
    )
    Post findByPaperIdNotInRebuttal(long id);

    @Query("select size(post.replies) from Post post " +
            "where post.id=:id "
    )
    int countRepliesById(long id);

}
